<?php
$link_type = config('link_type');
if (!isset($type)) $type="";
if (!isset($link_url)) $link_url="";
?>
<div class="form-group">
    <label class="control-label col-xs-2">
        跳转类型
        <span style="color: #FF0000;">*</span>
    </label>
    <div class="col-xs-9">
        <select id="type-selector" name="[type-name]" class="form-control" tabindex="-1" required>
            <option value="">
                无选择
            </option>
            {volist name="link_type" id="item"}

            <option value="{$item.type}" {if condition="$type==$item['type']"}selected{/if} >{$item.type_name}</option>

            {/volist}
        </select>
    </div>
</div>

<div class="form-group">
    <label class="control-label col-xs-2">
        跳转地址
        <span id="link_url_tit" style="display:none;color: #FF0000;">*</span>
    </label>
    <div class="col-xs-9">
        <input id="link_url" value="{$link_url}" type="text" class="form-control" name="[link-url-name]" maxlength="255" placeholder="">
    </div>
</div>

<script src="__PUBLIC__/vendors/select2/js/select2.min.js"></script>
<script>
    $(function(){
        //获取分类
        $("#type-selector").select2({
            placeholder: "请选择跳转类型",
            allowClear: true
        });
        var link_type = '{php} echo json_encode($link_type);{/php}';
        link_type = JSON.parse(link_type);
        $("#type-selector").change(function () {
            var type = parseInt($(this).val());
            var placeholder = link_type[type]['placeholder'];
            $("#link_url").attr('placeholder',placeholder);
            var link_need = link_type[type]['link_need'];
            $("#link_url-error").remove();
            $("#link_url").val('');
            if(link_need==1){
                $("#link_url_tit").show();
                $("#link_url").attr('required','required');
            }else{
                $("#link_url_tit").hide();
                $("#link_url").removeAttr('required');
            }
        });
    });
</script>